﻿using EnvDTE;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace Axiom.CodeManifold
{
	public static class CodeTypeExtensions
	{
		public static string GetTypeAsString(this CodeTypeRef codeType)
		{
			var fullname = codeType.AsFullName;
			var type = codeType.CodeType.Name;

			Regex regex = new Regex(@"^.*\<(.*)\>$");
			Match m = regex.Match(fullname);
			if (m.Success)
			{
				string gentypes = m.Groups[1].ToString();
				var parts = gentypes.Split(new char[] { ',' });

				var list = new List<string>();
				foreach (var part in parts)
				{
					list.Add(part.Split('.').Last());
				}
				type += "<" + string.Join(", ", list.ToArray()) + ">";
			}

			return type;
		}
	}
}
